package com.ngocvo.QuanLyThuChi;

import java.util.ArrayList;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

public class Example extends Activity {    
    //Các hằng dùng cho tạo Option Menu
    private static final int DELETE_WORK = Menu.FIRST;
    private static final int ABOUT = Menu.FIRST + 2;
    
    ArrayList<Work> array;
    ListWorkAdapter arrayAdapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.thongke_layout);
        
        array = new ArrayList<Work>();
        
       /* Work work = new Work();
        work.setName("Lương tháng 3");
        work.setAmount("99000");
        work.setFlowDate("2011-03-31 17:00:00");
        work.setStatus(Short.parseShort("1"));*/
        /*Work work = new Work("Lương", "99000");
        work.setFlowDate("2011-03-31 17:00:00");
        array.add(work);*/
        
        CashFlowData CFData = new CashFlowData(Example.this);
        ArrayList<Work> cashList = CFData.getAllByFlowType(0);
        array = cashList;
        
        arrayAdapter = new ListWorkAdapter(this, 
                R.layout.list, array);
        
        //Tạo list view cho danh sách công việc
        final ListView list = (ListView) findViewById(R.id.cashList);
        list.setAdapter(arrayAdapter);
        
        /*OnClickListener add = new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (workEnter.getText().toString().equals("") ||
                        hourEdit.getText().toString().equals("") ||
                        minuteEdit.getText().toString().equals("")) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(Example.this);
                    builder.setTitle("Info missing");
                    builder.setMessage("Please enter all information of the work");
                    builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub                            
                        }                        
                    });
                    builder.show();
                }
                else {
                    String workContent = workEnter.getText().toString();
                    String timeContent = hourEdit.getText().toString() + ":"
                                    + minuteEdit.getText().toString();
                    //Work work = new Work(workContent, timeContent);
                    //array.add(0, work);
                    arrayAdapter.notifyDataSetChanged();
                    workEnter.setText("");
                    hourEdit.setText("");
                    minuteEdit.setText("");
                }
            }
            
        };
        
        button.setOnClickListener(add);*/        
    }
    
    //Tạo Option Menu
  /*  public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);        
        menu.add(0, DELETE_WORK, 0,"Delete" ).setIcon(android.R.drawable.ic_delete);        
        menu.add(0, ABOUT, 0,"About" ).setIcon(android.R.drawable.ic_menu_info_details);
        return true;
    }
    
    //Xử lý sự kiện khi các option trong Option Menu được lựa chọn
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {            
            case DELETE_WORK: {
                deleteCheckedWork();
                break;
            }            
            case ABOUT: {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("VietAndroid");
                builder.setMessage("AUTHOR:" + "\n" + "  Nguyen Anh Tuan" + "\n" + "SOURCE:" + "\n" + "  diendan.vietandroid.com");
                builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {                                    
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
                builder.setIcon(android.R.drawable.ic_dialog_info);
                builder.show();
                break;
            }
        }
        return true;
       }

    private void deleteCheckedWork() {
        if (array.size() > 0) {
            for (int i = array.size() - 1; i >= 0; i--) {
                if (array.get(i).isChecked()) {
                    array.remove(i);
                    arrayAdapter.notifyDataSetChanged();
                    continue;
                }
            }
        }        
    }*/
}